//
//  WFRefreshAdapter.m
//  WisdomFarm
//
//  Created by sky on 2017/12/20.
//  Copyright © 2017年 sky. All rights reserved.
//

#import "WFRefreshAdapter.h"

@interface WFRefreshAdapter()

@property (nonatomic, strong) UIScrollView *scrollView;

@end

@implementation WFRefreshAdapter

- (void)setDelegate:(id<WFRefreshProtocol>)delegate {
    _delegate = delegate;
    self.scrollView = [delegate mainScrollView];
    self.scrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(onTriggerRefresh:)];
}

- (void)onTriggerRefresh:(id)sender {
    @weakify(self);
    [self.delegate refreshDataWithCompletion:^(BOOL hasNext, NSError *error) {
        @strongify(self);
        [self.scrollView.mj_header endRefreshing];
    }];
}

@end
